package Catalogos;

import Componentes.InternalFrame;
import Componentes.RendersValidators.ButtonRenderPerfiles;
import Modelos.TblPantallas;
import Modelos.TblPantallasPerfiles;
import Modelos.TblPerfiles;
import java.awt.Font;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.KeyStroke;
import javax.swing.table.TableRowSorter;
public final class dlgPerfiles extends InternalFrame {


    protected static dlgPerfiles yo = null;
    private ButtonRenderPerfiles render = new ButtonRenderPerfiles(true);
    private AccionAgregarPantallas pantallas = new AccionAgregarPantallas();
    private TableRowSorter sorter;

    private dlgPerfiles() {
        initComponents();
        sorter = new TableRowSorter(tblPerfiles.getModel());
        tblPerfiles.setRowSorter(sorter);
        cargarPrpiedadesExtra();
        this.tblPerfiles.getColumnModel().getColumn(0).setCellRenderer(render);
        if (!Beans.isDesignTime()) {
            goBoxEntityManager.getTransaction().begin();
        }
        txtFiltro1.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent ke) {
                super.keyReleased(ke);
                if (!txtFiltro1.getText().equals(txtFiltro1.getFrase())) {
                    sorter.setRowFilter(javax.swing.RowFilter.regexFilter(txtFiltro1.getText()));
                }
            }
        });

        this.jProgressBar1.setValue(100);
        this.jProgressBar1.setString("Listo");
        dlgPantallas.setLocation(new Point(300, 200));
        dlgPantallas.setSize(350, 400);
        

    }

    public static dlgPerfiles getInstance() {
        if (yo == null) {
            yo = new dlgPerfiles();
        }
        return yo;
    }

    public void cargarPrpiedadesExtra() {

        int fontTam = Integer.parseInt(propiedades.getProperty("TamanoFuente", "12"));
        String fontName = propiedades.getProperty("NombreFuente", "Lucida Grande");
        int fontStyle = Integer.parseInt(propiedades.getProperty("EstiloFuente", "1"));
        this.tblPerfiles.setFont(new Font(fontName, fontStyle, fontTam));
        this.tblPerfiles.setRowHeight(Integer.parseInt(propiedades.getProperty("TamCelda", "18")));
        String osnom = System.getProperty("os.name");
        if (osnom.equals("Mac OS X")) {
            Launcher.Launcher.getInstance().a.requestUserAttention(true);
        }

    }

    @Override
    public void dispose() {
        super.dispose();
        GuardarPropiedad("TamanoFuente", "" + tblPerfiles.getFont().getSize());
        GuardarPropiedad("NombreFuente", tblPerfiles.getFont().getFontName());
        GuardarPropiedad("EstiloFuente", "" + tblPerfiles.getFont().getStyle());
        GuardarPropiedad("TamCelda", "" + tblPerfiles.getRowHeight());


    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        accionCancelar1 = new Acciones.Persistencia.AccionCancelar();
        accionEliminar1 = new Acciones.Persistencia.AccionEliminar();
        accionGuadar1 = new Acciones.Persistencia.AccionGuadar();
        accionNuevo1 = new Acciones.Persistencia.AccionNuevo();
        accionRefrescar1 = new Acciones.Persistencia.AccionRefrescar();
        accionAumentarFuente1 = new Acciones.Edicion.AccionAumentarFuente();
        accionDisminuirFuente1 = new Acciones.Edicion.AccionDisminuirFuente();
        accionPersonalizarFuente1 = new Acciones.Edicion.AccionPersonalizarFuente();
        goBoxEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("goBox").createEntityManager();
        tblPerfilesQuery = java.beans.Beans.isDesignTime() ? null : goBoxEntityManager.createQuery("SELECT t FROM TblPerfiles t");
        tblPerfilesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(new java.util.LinkedList(tblPerfilesQuery.getResultList()));
        buttonEditor1 = new Componentes.ButtonEditor();
        dlgPantallas = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        pnlRedondo3 = new org.edisoncor.gui.panel.PanelNice();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblDatos1 = new Componentes.tblDatos();
        tblPantallasQuery = java.beans.Beans.isDesignTime() ? null : goBoxEntityManager.createQuery("SELECT t FROM TblPantallas t");
        tblPantallasList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(new java.util.LinkedList(tblPantallasQuery.getResultList()));
        pantallasTransferHaandler1 = new Componentes.PantallasTransferHaandler();
        agregarVentana = new javax.swing.JPopupMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        EliminarVentana = new javax.swing.JPopupMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        separador = new javax.swing.JToolBar();
        btnNuevo = new Componentes.Button();
        btnEliminar = new Componentes.Button();
        btnCancelar = new Componentes.Button();
        btnGuardar = new Componentes.Button();
        jButton3 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton5 = new javax.swing.JButton();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(100, 0), new java.awt.Dimension(100, 0), new java.awt.Dimension(2000, 32767));
        jSeparator6 = new javax.swing.JToolBar.Separator();
        txtEspecial1 = new Componentes.Texfields.txtEspecial();
        jSeparator7 = new javax.swing.JToolBar.Separator();
        pnlRedondo1 = new org.edisoncor.gui.panel.PanelNice();
        txtFiltro1 = new Componentes.Texfields.txtFiltro();
        pnlRedondo2 = new org.edisoncor.gui.panel.PanelNice();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPerfiles = new Componentes.tblDatos();
        pnlPantallas = new org.edisoncor.gui.panel.PanelNice();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblDetalle = new Componentes.tblDatos();
        jSplitPane2 = new javax.swing.JSplitPane();
        jLabel2 = new javax.swing.JLabel();
        jSplitPane3 = new javax.swing.JSplitPane();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnuNuevo = new javax.swing.JMenuItem();
        mnuEliminar = new javax.swing.JMenuItem();
        mnuCancelar = new javax.swing.JMenuItem();
        mnuGuardar = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();

        accionCancelar1.setEm(goBoxEntityManager);
        accionCancelar1.setLs(tblPerfilesList);
        accionCancelar1.setQ(tblPerfilesQuery);

        accionEliminar1.setEm(goBoxEntityManager);
        accionEliminar1.setLs(tblPerfilesList);
        accionEliminar1.setTbl(tblPerfiles);

        accionGuadar1.setEm(goBoxEntityManager);
        accionGuadar1.setLs(tblPerfilesList);
        accionGuadar1.setValidador(render);

        accionNuevo1.setEm(goBoxEntityManager);
        accionNuevo1.setLs(tblPerfilesList);
        accionNuevo1.setO(new TblPerfiles());
        accionNuevo1.setTbl(tblPerfiles);

        accionRefrescar1.setEm(goBoxEntityManager);
        accionRefrescar1.setLs(tblPerfilesList);
        accionRefrescar1.setQ(tblPerfilesQuery);

        accionAumentarFuente1.setObjeto(tblPerfiles);

        accionDisminuirFuente1.setObjeto(tblPerfiles);

        accionPersonalizarFuente1.setElemento(tblPerfiles);

        dlgPantallas.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        dlgPantallas.setTitle("Ventanas del Sistema");
        dlgPantallas.setAlwaysOnTop(true);
        dlgPantallas.setMinimumSize(new java.awt.Dimension(150, 250));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        pnlRedondo3.setBackground(new java.awt.Color(220, 230, 240));
        pnlRedondo3.setMinimumSize(new java.awt.Dimension(200, 100));

        tblDatos1.setComponentPopupMenu(agregarVentana);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblPantallasList, tblDatos1);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane3.setViewportView(tblDatos1);
        tblDatos1.getColumnModel().getColumn(0).setMinWidth(140);
        tblDatos1.getColumnModel().getColumn(0).setPreferredWidth(160);
        tblDatos1.getColumnModel().getColumn(0).setMaxWidth(200);

        org.jdesktop.layout.GroupLayout pnlRedondo3Layout = new org.jdesktop.layout.GroupLayout(pnlRedondo3);
        pnlRedondo3.setLayout(pnlRedondo3Layout);
        pnlRedondo3Layout.setHorizontalGroup(
            pnlRedondo3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo3Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jScrollPane3)
                .add(8, 8, 8))
        );
        pnlRedondo3Layout.setVerticalGroup(
            pnlRedondo3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo3Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jScrollPane3)
                .add(8, 8, 8))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .add(4, 4, 4)
                .add(pnlRedondo3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(4, 4, 4))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(4, 4, 4)
                .add(pnlRedondo3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout dlgPantallasLayout = new org.jdesktop.layout.GroupLayout(dlgPantallas.getContentPane());
        dlgPantallas.getContentPane().setLayout(dlgPantallasLayout);
        dlgPantallasLayout.setHorizontalGroup(
            dlgPantallasLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        dlgPantallasLayout.setVerticalGroup(
            dlgPantallasLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pantallasTransferHaandler1.setLs(tblPerfilesList);
        pantallasTransferHaandler1.setLsPantallas(tblPantallasList);
        pantallasTransferHaandler1.setTblPantalla(tblDatos1);
        pantallasTransferHaandler1.setTblPerfil(tblPerfiles);

        jMenuItem2.setAction(new AccionAdd());
        agregarVentana.add(jMenuItem2);

        jMenuItem6.setAction(new AccionEliminarPantallas());
        EliminarVentana.add(jMenuItem6);

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle(Configuraciones.Configuraciones.NOMBRE_PERFILES);
        setFrameIcon(Configuraciones.Configuraciones.ICONO_PERFILES);

        separador.setBackground(new java.awt.Color(121, 137, 167));
        separador.setBorder(null);
        separador.setFloatable(false);
        separador.setRollover(true);

        btnNuevo.setAction(accionNuevo1);
        btnNuevo.setText("button1");
        btnNuevo.setBorderPainted(false);
        btnNuevo.setFocusable(false);
        btnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevo.setMargin(new java.awt.Insets(0, 0, 0, 0));
        btnNuevo.setMaximumSize(new java.awt.Dimension(35, 44));
        btnNuevo.setMinimumSize(new java.awt.Dimension(44, 44));
        btnNuevo.setPreferredSize(new java.awt.Dimension(35, 44));
        btnNuevo.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(btnNuevo);

        btnEliminar.setAction(accionEliminar1);
        btnEliminar.setText("button2");
        btnEliminar.setBorderPainted(false);
        btnEliminar.setFocusable(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEliminar.setMargin(new java.awt.Insets(0, 0, 0, 0));
        btnEliminar.setMaximumSize(new java.awt.Dimension(35, 44));
        btnEliminar.setMinimumSize(new java.awt.Dimension(35, 44));
        btnEliminar.setPreferredSize(new java.awt.Dimension(35, 44));
        btnEliminar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(btnEliminar);

        btnCancelar.setAction(accionCancelar1);
        btnCancelar.setText("button3");
        btnCancelar.setBorderPainted(false);
        btnCancelar.setFocusable(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setMargin(new java.awt.Insets(0, 0, 0, 0));
        btnCancelar.setMaximumSize(new java.awt.Dimension(35, 44));
        btnCancelar.setMinimumSize(new java.awt.Dimension(44, 44));
        btnCancelar.setPreferredSize(new java.awt.Dimension(35, 44));
        btnCancelar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(btnCancelar);

        btnGuardar.setAction(accionGuadar1);
        btnGuardar.setText("button4");
        btnGuardar.setBorderPainted(false);
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setMargin(new java.awt.Insets(0, 0, 0, 0));
        btnGuardar.setMaximumSize(new java.awt.Dimension(35, 44));
        btnGuardar.setMinimumSize(new java.awt.Dimension(44, 44));
        btnGuardar.setPreferredSize(new java.awt.Dimension(35, 44));
        btnGuardar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(btnGuardar);

        jButton3.setAction(accionRefrescar1);
        jButton3.setBorderPainted(false);
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jButton3.setMaximumSize(new java.awt.Dimension(35, 44));
        jButton3.setPreferredSize(new java.awt.Dimension(35, 44));
        jButton3.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(jButton3);

        jSeparator1.setBackground(new java.awt.Color(255, 255, 255));
        jSeparator1.setForeground(new java.awt.Color(255, 255, 255));
        separador.add(jSeparator1);

        jButton1.setAction(accionAumentarFuente1);
        jButton1.setBorderPainted(false);
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jButton1.setMaximumSize(new java.awt.Dimension(35, 44));
        jButton1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(jButton1);

        jButton2.setAction(accionDisminuirFuente1);
        jButton2.setBorderPainted(false);
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jButton2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(jButton2);

        jButton4.setAction(accionPersonalizarFuente1);
        jButton4.setBorderPainted(false);
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setMaximumSize(new java.awt.Dimension(35, 44));
        jButton4.setPreferredSize(new java.awt.Dimension(35, 44));
        jButton4.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(jButton4);

        jSeparator2.setForeground(new java.awt.Color(255, 255, 255));
        separador.add(jSeparator2);

        jButton5.setAction(pantallas);
        jButton5.setBorderPainted(false);
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jButton5.setMaximumSize(new java.awt.Dimension(35, 44));
        jButton5.setMinimumSize(new java.awt.Dimension(35, 44));
        jButton5.setPreferredSize(new java.awt.Dimension(35, 44));
        jButton5.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        separador.add(jButton5);
        separador.add(filler1);

        jSeparator6.setForeground(new java.awt.Color(255, 255, 255));
        separador.add(jSeparator6);

        txtEspecial1.setAnchoDeBorde(0.0F);
        txtEspecial1.setColorDeBorde(new java.awt.Color(121, 137, 167));
        txtEspecial1.setFrase("Buscar (ctrl + B)");
        txtEspecial1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/Iconos/filtrar.png"))); // NOI18N
        txtEspecial1.setMaximumSize(new java.awt.Dimension(130, 22));
        txtEspecial1.setPreferredSize(new java.awt.Dimension(130, 20));
        separador.add(txtEspecial1);

        jSeparator7.setForeground(new java.awt.Color(121, 137, 167));
        separador.add(jSeparator7);

        pnlRedondo1.setBackground(new java.awt.Color(220, 230, 240));

        txtFiltro1.setFrase("Ingrese su Busqueda Aqui");

        org.jdesktop.layout.GroupLayout pnlRedondo1Layout = new org.jdesktop.layout.GroupLayout(pnlRedondo1);
        pnlRedondo1.setLayout(pnlRedondo1Layout);
        pnlRedondo1Layout.setHorizontalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, pnlRedondo1Layout.createSequentialGroup()
                .add(4, 4, 4)
                .add(txtFiltro1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(4, 4, 4))
        );
        pnlRedondo1Layout.setVerticalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo1Layout.createSequentialGroup()
                .add(4, 4, 4)
                .add(txtFiltro1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(2, 2, 2))
        );

        pnlRedondo2.setBackground(new java.awt.Color(220, 230, 240));

        jSplitPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane1.setDividerLocation(200);
        jSplitPane1.setDividerSize(6);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setOneTouchExpandable(true);
        jSplitPane1.setOpaque(false);

        tblPerfiles.setDragEnabled(true);

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblPerfilesList, tblPerfiles);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idperfil}"));
        columnBinding.setColumnName("");
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${perfil}"));
        columnBinding.setColumnName("Perfil");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${estatus}"));
        columnBinding.setColumnName("Estatus");
        columnBinding.setColumnClass(Boolean.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblPerfiles);
        tblPerfiles.getColumnModel().getColumn(0).setMinWidth(20);
        tblPerfiles.getColumnModel().getColumn(0).setPreferredWidth(20);
        tblPerfiles.getColumnModel().getColumn(0).setMaxWidth(20);
        tblPerfiles.getColumnModel().getColumn(0).setCellEditor(buttonEditor1);
        tblPerfiles.getColumnModel().getColumn(1).setMinWidth(50);
        tblPerfiles.getColumnModel().getColumn(1).setPreferredWidth(60);
        tblPerfiles.getColumnModel().getColumn(1).setMaxWidth(80);
        tblPerfiles.getColumnModel().getColumn(2).setMinWidth(120);
        tblPerfiles.getColumnModel().getColumn(2).setPreferredWidth(135);
        tblPerfiles.getColumnModel().getColumn(2).setMaxWidth(150);
        tblPerfiles.getColumnModel().getColumn(4).setMinWidth(60);
        tblPerfiles.getColumnModel().getColumn(4).setPreferredWidth(60);
        tblPerfiles.getColumnModel().getColumn(4).setMaxWidth(60);

        jSplitPane1.setTopComponent(jScrollPane1);

        pnlPantallas.setBackground(new java.awt.Color(255, 255, 255));

        tblDetalle.setComponentPopupMenu(EliminarVentana);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.tblPantallasPerfilesCollection}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblPerfiles, eLProperty, tblDetalle);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tblpantallasIdpantalla.nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tblpantallasIdpantalla.descripcion}"));
        columnBinding.setColumnName("Descripción");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${modificar}"));
        columnBinding.setColumnName("Modificar");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${estatus}"));
        columnBinding.setColumnName("Estatus");
        columnBinding.setColumnClass(Boolean.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblPerfiles, org.jdesktop.beansbinding.ELProperty.create("${font}"), tblDetalle, org.jdesktop.beansbinding.BeanProperty.create("font"));
        bindingGroup.addBinding(binding);

        jScrollPane2.setViewportView(tblDetalle);

        org.jdesktop.layout.GroupLayout pnlPantallasLayout = new org.jdesktop.layout.GroupLayout(pnlPantallas);
        pnlPantallas.setLayout(pnlPantallasLayout);
        pnlPantallasLayout.setHorizontalGroup(
            pnlPantallasLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlPantallasLayout.createSequentialGroup()
                .add(4, 4, 4)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE)
                .add(4, 4, 4))
        );
        pnlPantallasLayout.setVerticalGroup(
            pnlPantallasLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlPantallasLayout.createSequentialGroup()
                .add(4, 4, 4)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .add(4, 4, 4))
        );

        jSplitPane1.setRightComponent(pnlPantallas);

        org.jdesktop.layout.GroupLayout pnlRedondo2Layout = new org.jdesktop.layout.GroupLayout(pnlRedondo2);
        pnlRedondo2.setLayout(pnlRedondo2Layout);
        pnlRedondo2Layout.setHorizontalGroup(
            pnlRedondo2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo2Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jSplitPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .add(8, 8, 8))
        );
        pnlRedondo2Layout.setVerticalGroup(
            pnlRedondo2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo2Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .add(8, 8, 8))
        );

        jSplitPane2.setBackground(new java.awt.Color(255, 255, 255));
        jSplitPane2.setBorder(null);
        jSplitPane2.setDividerLocation(200);
        jSplitPane2.setDividerSize(0);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jSplitPane2.setRightComponent(jLabel2);

        jSplitPane3.setBorder(null);
        jSplitPane3.setDividerLocation(4);
        jSplitPane3.setDividerSize(0);
        jSplitPane3.setOpaque(false);

        jProgressBar1.setStringPainted(true);
        jSplitPane3.setRightComponent(jProgressBar1);

        jLabel1.setText("  ");
        jSplitPane3.setLeftComponent(jLabel1);

        jSplitPane2.setLeftComponent(jSplitPane3);

        jMenu1.setText("Archivo");

        mnuNuevo.setAction(accionNuevo1);
        jMenu1.add(mnuNuevo);

        mnuEliminar.setAction(accionEliminar1);
        jMenu1.add(mnuEliminar);

        mnuCancelar.setAction(accionCancelar1);
        jMenu1.add(mnuCancelar);

        mnuGuardar.setAction(accionGuadar1);
        jMenu1.add(mnuGuardar);

        jMenuItem9.setAction(accionRefrescar1);
        jMenu1.add(jMenuItem9);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edición");

        jMenu3.setText("Fuente");

        jMenuItem3.setAction(accionAumentarFuente1);
        jMenu3.add(jMenuItem3);

        jMenuItem5.setAction(accionDisminuirFuente1);
        jMenu3.add(jMenuItem5);

        jMenuItem4.setAction(accionPersonalizarFuente1);
        jMenu3.add(jMenuItem4);

        jMenu2.add(jMenu3);

        jMenuItem1.setAction(pantallas);
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(separador, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .add(4, 4, 4)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(pnlRedondo2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(4, 4, 4))
            .add(jSplitPane2)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(separador, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(4, 4, 4)
                .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(4, 4, 4)
                .add(pnlRedondo2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(4, 4, 4)
                .add(jSplitPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPopupMenu EliminarVentana;
    private Acciones.Edicion.AccionAumentarFuente accionAumentarFuente1;
    private Acciones.Persistencia.AccionCancelar accionCancelar1;
    private Acciones.Edicion.AccionDisminuirFuente accionDisminuirFuente1;
    private Acciones.Persistencia.AccionEliminar accionEliminar1;
    private Acciones.Persistencia.AccionGuadar accionGuadar1;
    private Acciones.Persistencia.AccionNuevo accionNuevo1;
    private Acciones.Edicion.AccionPersonalizarFuente accionPersonalizarFuente1;
    private Acciones.Persistencia.AccionRefrescar accionRefrescar1;
    private javax.swing.JPopupMenu agregarVentana;
    private Componentes.Button btnCancelar;
    private Componentes.Button btnEliminar;
    private Componentes.Button btnGuardar;
    private Componentes.Button btnNuevo;
    private Componentes.ButtonEditor buttonEditor1;
    private javax.swing.JDialog dlgPantallas;
    private javax.swing.Box.Filler filler1;
    private javax.persistence.EntityManager goBoxEntityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JToolBar.Separator jSeparator7;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JMenuItem mnuCancelar;
    private javax.swing.JMenuItem mnuEliminar;
    private javax.swing.JMenuItem mnuGuardar;
    private javax.swing.JMenuItem mnuNuevo;
    private Componentes.PantallasTransferHaandler pantallasTransferHaandler1;
    private org.edisoncor.gui.panel.PanelNice pnlPantallas;
    private org.edisoncor.gui.panel.PanelNice pnlRedondo1;
    private org.edisoncor.gui.panel.PanelNice pnlRedondo2;
    private org.edisoncor.gui.panel.PanelNice pnlRedondo3;
    private javax.swing.JToolBar separador;
    private Componentes.tblDatos tblDatos1;
    private Componentes.tblDatos tblDetalle;
    private java.util.List<Modelos.TblPantallas> tblPantallasList;
    private javax.persistence.Query tblPantallasQuery;
    private Componentes.tblDatos tblPerfiles;
    private java.util.List<Modelos.TblPerfiles> tblPerfilesList;
    private javax.persistence.Query tblPerfilesQuery;
    private Componentes.Texfields.txtEspecial txtEspecial1;
    private Componentes.Texfields.txtFiltro txtFiltro1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public class AccionAgregarPantallas extends AbstractAction {

        public AccionAgregarPantallas() {
            putValue(NAME, "Ventanas ");
            putValue(SHORT_DESCRIPTION, "Agregar Ventanas a  los perfiles.");
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_V));
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
            putValue(SMALL_ICON, Configuraciones.Configuraciones.ICONO_VENTANAS);


        }

        @Override
        public void actionPerformed(ActionEvent ae) {    
            dlgPantallas.setVisible(true);
        }
    }

    public class AccionAdd extends AbstractAction {

        public AccionAdd() {
            putValue(NAME, "Agregar ");
            putValue(SHORT_DESCRIPTION, "Agregar Ventanas al  perfil seleccioando.");
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_A));
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A,
                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
            putValue(SMALL_ICON, Configuraciones.Configuraciones.ICONO_MAS);


        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            int[] selected = tblDatos1.getSelectedRows();
            List<TblPantallas> PantallasAdd = new ArrayList<TblPantallas>(selected.length);
            for (int i = 0; i < selected.length; i++) {
                TblPantallas u = (TblPantallas) tblPantallasList.get(tblDatos1.convertRowIndexToModel(selected[i]));
                PantallasAdd.add(u);
            }
            
            int rowSelected= tblPerfiles.getSelectedRow();
            if(rowSelected!=-1){
                TblPerfiles perfil=tblPerfilesList.get(rowSelected);
                Collection<TblPantallasPerfiles> lstNueva = new ArrayList<TblPantallasPerfiles>();
                
                
                for (TblPantallas ventana : PantallasAdd) {
                           if(!Esta(ventana,perfil)){
                            TblPantallasPerfiles pantalla=new TblPantallasPerfiles(null,false, false, perfil, ventana);
                            goBoxEntityManager.persist(pantalla);
                            lstNueva.add(pantalla);
                           }
                }
                
                lstNueva.addAll(perfil.getTblPantallasPerfilesCollection());
                perfil.setTblPantallasPerfilesCollection(lstNueva);
                tblDetalle.repaint();
            }

           
        }
        
        
        public boolean Esta(TblPantallas pan,TblPerfiles perf ){
            for(TblPantallasPerfiles pant:perf.getTblPantallasPerfilesCollection())
                if(pant.getTblpantallasIdpantalla().equals(pan))
                    return true;

        return false;
        
        }
    }
    
    
        public class AccionEliminarPantallas extends AbstractAction {

        public AccionEliminarPantallas() {
            putValue(NAME, "Eliminar");
            putValue(SHORT_DESCRIPTION, "Eliminar Ventanas a los perfiles.");
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R,
                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
            putValue(SMALL_ICON, Configuraciones.Configuraciones.ICONO_MENOS);


        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            int selected = tblPerfiles.getSelectedRow();
            Collection<TblPantallasPerfiles> det = new ArrayList<TblPantallasPerfiles>();
            det.addAll(tblPerfilesList.get(selected).getTblPantallasPerfilesCollection());
            int select = tblDetalle.getSelectedRow();
            int i=0;
           
            for (TblPantallasPerfiles pantalla :  tblPerfilesList.get(selected).getTblPantallasPerfilesCollection()) {
                if(i==select){
                    goBoxEntityManager.remove(pantalla);
                    det.remove(pantalla);
                    break;
                }
                i++;
            }
           
            tblPerfilesList.get(selected).setTblPantallasPerfilesCollection(det);
            tblDetalle.repaint();

        }
    }

}
